//
//  LUntilsTools.m
//  Q1603_0703
//
//  Created by LuSW on 16/7/4.
//  Copyright © 2016年 rimi. All rights reserved.
//

#import "LUtilityTools.h"
#import "AppDelegate.h"

@interface LUtilityTools ()


@end

@implementation LUtilityTools



+ (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title ? title:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:sureAction];
    [[LUtilityTools keyPresentingViewController] presentViewController:alertController animated:YES completion:nil];
}

+ (void)showAlertWithTitle:(NSString *)title message:(NSString *)message buttonAction:(void (^)())buttonAction {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title ? title:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (buttonAction) {
            buttonAction();
        }
    }];
    [alertController addAction:sureAction];
    
    [[LUtilityTools keyPresentingViewController] presentViewController:alertController animated:YES completion:nil];
}

+ (void)showAlertWithTitle:(NSString *)title message:(NSString *)message SureStr:(NSString *)sureStr buttonAction:(void (^)())buttonAction {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title ? title:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:sureStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (buttonAction) {
            buttonAction();
        }
    }];
    [alertController addAction:sureAction];
    
    [[LUtilityTools keyPresentingViewController] presentViewController:alertController animated:YES completion:nil];
}


+ (void)showAlertWithTitle:(NSString *)title message:(NSString *)message actionsMsg:(NSArray *)actionsMsg buttonActions:(void (^)(int))buttonActions {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title ? title:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    int index = 0;
    for (NSString *actionMsg in actionsMsg) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:actionMsg style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (buttonActions) {
                buttonActions(index);
            }
        }];
        [alertController addAction:action];
        index++;
    }
    [[LUtilityTools keyPresentingViewController] presentViewController:alertController animated:YES completion:nil];

}



+ (void)showAlertWithTitle:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)canceltitle buttonAction:(void (^)())buttonActions sureTitle:(NSString *)sureTitle ButtonAction:(void (^)())buttonAction{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *sureActions = [UIAlertAction actionWithTitle:canceltitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [sureActions setValue:[UIColor blackColor] forKey:@"titleTextColor"];
    
    [alertController addAction:sureActions];
    
    
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:sureTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (buttonAction) {
            buttonAction();
        }
    }];
    [sureAction setValue:[UIColor redColor] forKey:@"titleTextColor"];
    
    [alertController addAction:sureAction];
    
    [[LUtilityTools keyPresentingViewController] presentViewController:alertController animated:YES completion:nil];

    
    
}






+ (UIViewController *)keyPresentingViewController {
    UIViewController *presentVC = [[UIApplication sharedApplication] keyWindow].rootViewController;
    while (presentVC.presentedViewController) {
        presentVC = presentVC.presentedViewController;
    }
    return presentVC;
}




+(CGSize)string:(NSString *)str sizeWithFont:(CGFloat)font{
    CGSize size = [str sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}];
    return size;
    
}

//使字体从右向左滚动
+ (void)AnimationWithLabel:(UILabel*)labelShow;
{
    CGRect frame = labelShow.frame;
    frame.origin.x = 5;
    labelShow.frame = frame;
    [UIView beginAnimations:@"testAnimation" context:NULL];
    [UIView setAnimationDuration:6.0f];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatAutoreverses:NO];
    [UIView setAnimationRepeatCount:90];
    frame = labelShow.frame;
    frame.origin.x = -100;
    labelShow.frame = frame;
    [UIView commitAnimations];
}






@end










